// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;
#include "SQLUnnestTableSource.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"

SQLUnnestTableSource::SQLUnnestTableSource()
{
  items = std::make_shared<std::list<SQLExpr_ptr>>();
  columns = std::make_shared<std::list<SQLName_ptr>>();
}

// @Override
void SQLUnnestTableSource::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(SQLUnnestTableSource)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(items);
    acceptChild(v, tmp1);
    SQLObject_list_ptr tmp2 = ListTran::tran_class<SQLName, SQLObject>(columns);
    acceptChild(v, tmp2);
  }
  v->endVisit(SharedObject(SQLUnnestTableSource));
}

SQLName_list_ptr SQLUnnestTableSource::getColumns()
{
  return columns;
}

void SQLUnnestTableSource::addColumn(SQLName_ptr column)
{
  column->setParent(SharedObject(SQLUnnestTableSource));
  this->columns->push_back(column);
}

BOOL_ptr SQLUnnestTableSource::isOrdinality()
{
  return ordinality;
}

void SQLUnnestTableSource::setOrdinality(BOOL_ptr ordinality)
{
  this->ordinality = ordinality;
}

SQLExpr_list_ptr SQLUnnestTableSource::getItems()
{
  return items;
}

void SQLUnnestTableSource::addItem(SQLExpr_ptr item)
{
  item->setParent(SharedObject(SQLUnnestTableSource));
  this->items->push_back(item);
}

SQLObject_ptr SQLUnnestTableSource::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLUnnestTableSource>(new SQLUnnestTableSource());
  std::shared_ptr<SQLUnnestTableSource> x = std::dynamic_pointer_cast<SQLUnnestTableSource>(clone_tmp);
  // SQLUnnestTableSource x = new SQLUnnestTableSource();

  for (SQLExpr_ptr item : *items)
  {
    SQLExpr_ptr item2 = std::dynamic_pointer_cast<SQLExpr>(item->clone());
    item2->setParent(x);
    x->items->push_back(item2);
  }

  for (SQLName_ptr column : *columns)
  {
    SQLName_ptr c2 = std::dynamic_pointer_cast<SQLName>(column->clone());
    c2->setParent(x);
    x->columns->push_back(c2);
  }

  x->alias = alias;

  return x;
}
